<nav class="navbar navbar-expand-lg navbar-light bg-light shadow-sm">
    <div class="container">
        <a class="navbar-brand" href="{{route('root')}}">ShopMall</a>
        <!-- Left Side Of Navbar -->
        <ul class="navbar-nav mr-auto">
            <!-- 顶部分类菜单开始 -->
            <!-- 判断模板是否有 $categoryTree 变量 -->
            @if(isset($categoryTree))
                <li class="nav-item dropdown">
                    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" id="categoryTree">所有分类 <b class="caret"></b></a>
                    <ul class="dropdown-menu" aria-labelledby="categoryTree">
                        <!-- 遍历 $categoryTree 集合，将集合中的每一项以 $category 变量注入 layouts._category_item 模板中并渲染 -->
                        @each('layouts._category_item', $categoryTree, 'category')
                    </ul>
                </li>
            @endif
            <!-- 顶部分类菜单结束 -->
        </ul>
        <div class="navbar-nav navbar-right">
            <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarSupportedContent">
                <ul class="navbar-nav mr-auto">
                    @guest
                        <li class="nav-item">
                            <a class="nav-link" href="{{route('register')}}">注册</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="{{route('login')}}">登录</a>
                        </li>
                    @else
                        <li class="nav-item">
                            <a class="nav-link mt-2" href="{{ route('cart.index') }}"><i class="fa fa-shopping-cart"></i></a>
                        </li>
                        <li class="nav-item dropdown">
                            <a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-expanded="false">
                                <img class="img-thumbnail" width="40" src="{{url('fakers/avatars/avatar.png')}}" alt="{{Auth::user()->name}}">
                                {{Auth::user()->name}}
                            </a>
                            <div class="dropdown-menu">
                                <a class="dropdown-item text-center" href="{{route('user_addresses.index')}}">收货地址</a>
                                <a class="dropdown-item text-center" href="{{ route('orders.index')}}" >我的订单</a>
                                <a class="dropdown-item text-center" href="{{ route('installments.index') }}" >分期付款</a>
                                <a class="dropdown-item text-center" href="{{ route('products.favorites') }}" >我的收藏</a>
                                <a class="dropdown-item text-center" href="#"
                                onclick="event.preventDefault();document.getElementById('form-logout').submit()"
                                >退出登录</a>
                                <form action="{{route('logout')}}" style="display: none;" id="form-logout" method="post">
                                    @csrf
                                </form>
                            </div>
                        </li>
                    @endguest

                </ul>
            </div>
        </div>
    </div>
</nav>
